﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class TechnologyFormulaConfig : POBaseConfig<TechnologyFormulaPO>
    {
        public override void InitializeData(EntityTypeBuilder<TechnologyFormulaPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<TechnologyFormulaPO> builder, ref int index)
        {
            builder.HasComment("工艺公式表");
            builder.Property(entity => entity.TechnologyRouteProcessId).ConfigColumn("TECHNOLOGY_ROUTE_PROCESS_ID", "工艺路径工序ID").HasColumnOrder(index++);
            builder.Property(entity => entity.Step).ConfigColumn("STEP", "工步").HasColumnOrder(index++);
            builder.Property(entity => entity.ParamCode).ConfigColumn("PARAM_CODE", "参数编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.StateCode).ConfigColumn("STATE_CODE", "状态编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Formula).ConfigColumn("FORMULA", "公式", 2000, true).HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
            builder.HasMany(entity => entity.TechnologyFormulaParamList).WithOne(entity => entity.TechnologyFormula).HasForeignKey(entity => entity.TechnologyFormulaId).HasConstraintName("FK_B_TECHNOLOGYFORMULAPARAM").IsRequired().OnDelete(DeleteBehavior.Restrict);
        }

        public override void MapIndex(EntityTypeBuilder<TechnologyFormulaPO> builder)
        {
            builder.HasIndex(entity => new { entity.TechnologyRouteProcessId, entity.Step, entity.ParamCode, entity.WarehouseCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();
        }
    }
}
